# 1. Source functions ----
source("functions/graphical_par.R")
source("functions/theme_graph.R")
source("functions/pred_vbgf.R")
# 2. Required packages ----
library(tidyverse)
library(kableExtra)
library(formattable)
library(rfishbase)
library(readxl)
library(plotly)
# 3. Set theme_graph() as the default ggplot theme ----
theme_set(theme_graph())
# 4. Load data ----
data_complete <- read.csv("./../data/back-calculated-size-at-age_morat-et-al.csv")data_complete %>%
filter(!is.na(Li_sp_m)) %>%
summarize_at(vars("ID", "Species", "Family"), n_distinct, na.rm = TRUE) %>%
bind_rows(data_complete %>%
summarize_at(vars("ID", "Species", "Family"), n_distinct, na.rm = TRUE), .) %>%
mutate(Type = c("All data", "Back-calculated"), .before = 1) %>%
kable(.,
col.names = c("", "Individual", "Species", "Family"),
caption = "Table 1. Comparison of numbers of individuals, species and family for the overall dataset and for back-calculated data") %>%
kable_styling(bootstrap_options = c("striped", "hover"))| Individual | Species | Family | |
|---|---|---|---|
| All data | 855 | 51 | 16 |
| Back-calculated | 710 | 45 | 16 |
data_complete %>%
group_by(Species) %>%
summarise(n = length(unique(ID)),
min_lencap = round(min(Lcpt, na.rm = TRUE), 0),
max_lencap = round(max(Lcpt, na.rm = TRUE), 0),
max_age = max(Agei, na.rm = TRUE)) %>%
kable(.,
col.names = c("Species", "n", "Min length (TL, mm)", "Max length (TL, mm)", "Age max (years)"),
caption = "Table 2. Number of individuals, minimum and maximum total length (mm) and maximum age, by species") %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
column_spec(1, italic = T)| Species | n | Min length (TL, mm) | Max length (TL, mm) | Age max (years) |
|---|---|---|---|---|
| Abudefduf sexfasciatus | 16 | 51 | 172 | 13 |
| Acanthurus achilles | 17 | 130 | 246 | 27 |
| Acanthurus lineatus | 8 | 123 | 362 | 23 |
| Acanthurus nigricans | 8 | 150 | 210 | 9 |
| Acanthurus pyroferus | 18 | 51 | 230 | 19 |
| Acanthurus triostegus | 18 | 147 | 194 | 12 |
| Balistapus undulatus | 22 | 41 | 283 | 18 |
| Caranx melampygus | 7 | 368 | 712 | 15 |
| Centropyge bispinosa | 9 | 28 | 80 | 11 |
| Centropyge flavissima | 28 | 47 | 150 | 27 |
| Cephalopholis argus | 41 | 120 | 450 | 21 |
| Cephalopholis urodeta | 8 | 150 | 214 | 17 |
| Chaetodon citrinellus | 13 | 55 | 101 | 6 |
| Chaetodon ornatissimus | 10 | 122 | 175 | 10 |
| Cheilinus chlorourus | 8 | 96 | 299 | 6 |
| Chlorurus spilurus | 34 | 164 | 344 | 16 |
| Chromis iomelas | 20 | 39 | 61 | 5 |
| Chromis viridis | 6 | 115 | 148 | 9 |
| Ctenochaetus marginatus | 15 | 99 | 270 | 13 |
| Ctenochaetus striatus | 26 | 153 | 218 | 17 |
| Dascyllus aruanus | 20 | 51 | 71 | 7 |
| Dascyllus flavicaudus | 8 | 89 | 104 | 13 |
| Epibulus insidiator | 17 | 157 | 350 | 16 |
| Epinephelus fasciatus | 10 | 123 | 256 | 13 |
| Epinephelus hexagonatus | 16 | 139 | 268 | 14 |
| Epinephelus merra | 46 | 108 | 261 | 17 |
| Epinephelus polyphekadion | 14 | 252 | 514 | 20 |
| Gnathodentex aureolineatus | 8 | 197 | 255 | 17 |
| Gymnosarda unicolor | 4 | 499 | 985 | 7 |
| Halichoeres trimaculatus | 13 | 64 | 186 | 5 |
| Lutjanus fulvus | 12 | 195 | 289 | 21 |
| Lutjanus gibbus | 17 | 113 | 155 | 1 |
| Lutjanus kasmira | 37 | 70 | 326 | 30 |
| Monotaxis grandoculis | 9 | 200 | 505 | 20 |
| Mulloidichthys flavolineatus | 14 | 257 | 311 | 6 |
| Myripristis berndti | 30 | 147 | 279 | 24 |
| Naso lituratus | 17 | 228 | 432 | 10 |
| Naso unicornis | 4 | 488 | 613 | 17 |
| Odonus niger | 18 | 176 | 350 | 16 |
| Ostorhinchus angustatus | 15 | 46 | 83 | 6 |
| Ostorhinchus apogonoides | 30 | 52 | 96 | 7 |
| Parupeneus barberinus | 16 | 82 | 496 | 6 |
| Plectropomus laevis | 31 | 356 | 957 | 22 |
| Pristiapogon taeniopterus | 32 | 51 | 104 | 8 |
| Sargocentron microstoma | 23 | 62 | 204 | 13 |
| Scarus psittacus | 8 | 195 | 311 | 6 |
| Siganus argenteus | 11 | 236 | 388 | 13 |
| Siganus spinus | 4 | 199 | 254 | 3 |
| Stegastes albifasciatus | 7 | 43 | 94 | 8 |
| Stegastes nigricans | 14 | 45 | 138 | 13 |
| Zebrasoma scopas | 18 | 110 | 166 | 24 |
data_complete %>%
group_by(Species, Location) %>%
summarise(n = length(unique(ID))) %>%
pivot_wider(names_from = Location, values_from = n) %>%
mutate(Gambiers = cell_spec(Gambiers, "html", color = ifelse(is.na(Gambiers), "white", "#446CB3")),
Hao = cell_spec(Hao, "html", color = ifelse(is.na(Hao), "white", "#446CB3")),
Marquesas = cell_spec(Marquesas, "html", color = ifelse(is.na(Marquesas), "white", "#446CB3")),
Moorea = cell_spec(Moorea, "html", color = ifelse(is.na(Moorea), "white", "#446CB3")),
Manuae = cell_spec(Manuae, "html", color = ifelse(is.na(Manuae), "white", "#446CB3")),
Tuamotu = cell_spec(Tuamotu, "html", color = ifelse(is.na(Tuamotu), "white", "#446CB3"))) %>%
kable(.,
format = "html", escape = FALSE,
caption = "Table 3. Number of individuals of each species by location") %>%
kable_styling(bootstrap_options = c("striped", "hover")) %>%
column_spec(1, italic = T)| Species | Gambiers | Moorea | Manuae | Marquesas | Tuamotu | Hao |
|---|---|---|---|---|---|---|
| Abudefduf sexfasciatus | 11 | 5 | NA | NA | NA | NA |
| Acanthurus achilles | 7 | NA | 10 | NA | NA | NA |
| Acanthurus lineatus | NA | NA | NA | 8 | NA | NA |
| Acanthurus nigricans | NA | NA | NA | 8 | NA | NA |
| Acanthurus pyroferus | NA | NA | NA | 18 | NA | NA |
| Acanthurus triostegus | 3 | 11 | NA | 4 | NA | NA |
| Balistapus undulatus | NA | 14 | NA | 8 | NA | NA |
| Caranx melampygus | NA | 5 | NA | NA | 2 | NA |
| Centropyge bispinosa | NA | 9 | NA | NA | NA | NA |
| Centropyge flavissima | 9 | 7 | NA | 12 | NA | NA |
| Cephalopholis argus | 6 | 10 | NA | NA | 10 | 15 |
| Cephalopholis urodeta | 8 | NA | NA | NA | NA | NA |
| Chaetodon citrinellus | NA | 13 | NA | NA | NA | NA |
| Chaetodon ornatissimus | 4 | NA | NA | 6 | NA | NA |
| Cheilinus chlorourus | 2 | 6 | NA | NA | NA | NA |
| Chlorurus spilurus | 13 | 19 | NA | NA | 2 | NA |
| Chromis iomelas | NA | 20 | NA | NA | NA | NA |
| Chromis viridis | 6 | NA | NA | NA | NA | NA |
| Ctenochaetus marginatus | NA | NA | NA | 15 | NA | NA |
| Ctenochaetus striatus | 11 | 15 | NA | NA | NA | NA |
| Dascyllus aruanus | NA | 20 | NA | NA | NA | NA |
| Dascyllus flavicaudus | 8 | NA | NA | NA | NA | NA |
| Epibulus insidiator | 12 | 5 | NA | NA | NA | NA |
| Epinephelus fasciatus | NA | NA | NA | 10 | NA | NA |
| Epinephelus hexagonatus | NA | NA | NA | NA | NA | 16 |
| Epinephelus merra | 13 | 20 | NA | NA | NA | 13 |
| Epinephelus polyphekadion | NA | NA | NA | NA | NA | 14 |
| Gnathodentex aureolineatus | 8 | NA | NA | NA | NA | NA |
| Gymnosarda unicolor | 4 | NA | NA | NA | NA | NA |
| Halichoeres trimaculatus | 7 | 6 | NA | NA | NA | NA |
| Lutjanus fulvus | NA | 6 | NA | NA | 6 | NA |
| Lutjanus gibbus | NA | NA | NA | 17 | NA | NA |
| Lutjanus kasmira | 2 | NA | NA | 35 | NA | NA |
| Monotaxis grandoculis | 5 | 3 | NA | NA | 1 | NA |
| Mulloidichthys flavolineatus | NA | 14 | NA | NA | NA | NA |
| Myripristis berndti | 7 | 15 | NA | 8 | NA | NA |
| Naso lituratus | 11 | 6 | NA | NA | NA | NA |
| Naso unicornis | 4 | NA | NA | NA | NA | NA |
| Odonus niger | NA | 13 | NA | 5 | NA | NA |
| Ostorhinchus angustatus | NA | 15 | NA | NA | NA | NA |
| Ostorhinchus apogonoides | NA | NA | NA | 30 | NA | NA |
| Parupeneus barberinus | 5 | 4 | NA | 7 | NA | NA |
| Plectropomus laevis | 12 | NA | NA | NA | NA | 19 |
| Pristiapogon taeniopterus | NA | NA | NA | 32 | NA | NA |
| Sargocentron microstoma | NA | 17 | NA | 6 | NA | NA |
| Scarus psittacus | NA | 3 | NA | NA | 5 | NA |
| Siganus argenteus | 6 | 2 | NA | NA | 3 | NA |
| Siganus spinus | NA | 4 | NA | NA | NA | NA |
| Stegastes albifasciatus | NA | 7 | NA | NA | NA | NA |
| Stegastes nigricans | 3 | 11 | NA | NA | NA | NA |
| Zebrasoma scopas | 5 | 13 | NA | NA | NA | NA |
# 1. Number of NA by variable
data_complete %>%
summarise_all(~(sum(is.na(.)))) %>%
t(.) %>%
as.data.frame() %>%
kable(., col.names = c("NA"), caption = "Table 4. Number of rows with Non-Available (NA) data by variable") %>%
kable_styling(bootstrap_options = c("striped", "hover"))| NA | |
|---|---|
| Family | 0 |
| Genus | 0 |
| Species | 0 |
| ID | 0 |
| Agei | 0 |
| Ri | 387 |
| Agecpt | 0 |
| Rcpt | 0 |
| Lcpt | 0 |
| L0p | 0 |
| R0p | 2811 |
| Li_sp_m | 410 |
| Li_sp_sd | 410 |
| Li_sploc_m | 757 |
| Li_sploc_sd | 757 |
| Weight | 603 |
| Location | 0 |
| Observer | 0 |
ggplot(data_complete, aes(x = Agei, y = Ri)) +
geom_point(color = col_color_graph, fill = col_fill_graph, size = 1, shape = 21)+
theme(strip.text.x = element_text(size = 8, face = "italic"),
strip.background = element_rect(colour = "black", fill = col_facet, size = 1),
plot.title = element_text(colour = col_color_graph),
plot.subtitle = element_text(colour = "black")) +
facet_wrap(~Species, scales = "free", ncol = 5) +
labs(x = "Age (years)", y = "Radius at age i (mm)", title = "Check for outliers", subtitle = "agei vs radi")ggplot(data_complete, aes(x = Agei, y = Li_sp_m)) +
geom_point(color = col_color_graph, fill = col_fill_graph, size = 1, shape = 21)+
theme(strip.text.x = element_text(size = 8),
strip.background = element_rect(colour = "black", fill = col_facet, size = 1),
plot.title = element_text(colour = col_color_graph),
plot.subtitle = element_text(colour = "black"),
strip.text.y = element_text(angle = 360, face = "italic")) +
facet_grid(Species~Location, scales = "free") +
labs(x = "Age (years)", y = "Length at age i (mm)", title = "Check for outliers", subtitle = "agei vs li")ggplot(data_complete, aes(x = Agei, y = Li_sploc_m)) +
geom_point(color = col_color_graph, fill = col_fill_graph, size = 1, shape = 21)+
theme(strip.text.x = element_text(size = 8),
strip.background = element_rect(colour = "black", fill = col_facet, size = 1),
plot.title = element_text(colour = col_color_graph),
plot.subtitle = element_text(colour = "black"),
strip.text.y = element_text(angle = 360, face = "italic")) +
facet_grid(Species~Location, scales = "free") +
labs(x = "Age (years)", y = "Length at age i (mm)", title = "Check for outliers", subtitle = "agei vs li")# 1. Load and transform literature data ----
vb_litterature <- read_excel("./../data/von-bertalanffy-literature.xlsx", sheet = 1) %>%
mutate(Linf = ifelse(Size_unit == "cm", Linf*10, Linf),
Size_max = ifelse(Size_unit == "cm", Size_max*10, Size_max)) %>% # Convert values of 'Linf' and 'Size_unit' in mm
select(-Size_unit) %>%
mutate(Line = row_number()) %>%
group_by(Line) %>%
do(pred_vbgf(data = .))
# 2. Make the plot ----
A <- ggplot(data = vb_litterature, aes(x = Agei, y = Li, color = Reference, group = Line)) +
geom_line(show.legend = FALSE) +
labs(x = "Age (year)", y = "Length (mm)") +
facet_wrap(~Genus, scales = "free", ncol = 3) +
theme(legend.position='none')
# 3. Convert to plotly ----
ggplotly(A)